
#define _STANDALONE

#include <gdsl.h>

#include "endxml.h"

#include "io.h"

void processNode(xmlTextReaderPtr reader) {
    /* handling of a node in the tree */
char *name, *value;
	printf("depth: %d type: %d name: %s value: %s \n", 
				xmlTextReaderDepth(reader),
				xmlTextReaderNodeType(reader), 
				name= xmlTextReaderName(reader),
				value = xmlTextReaderValue(reader));
	
}

void print_node_xml_test(xmlNodePtr node){
//    xmlNodePtr aux =xmlNode(node);

		//printf("name: %s \n content: %s\n ", node->name,
		//			xmlNodeGetContent(node));
    word w = _read_word_from_xml(node);
    word_print(w);

}








void process(xmlNodePtr a_node){
  xmlNode *cur_node = NULL;

    for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
        if (cur_node->type == XML_ELEMENT_NODE &&
		strcmp(cur_node->name,TAG_WRD)==0) {
		word w = _read_word_from_xml(cur_node);
		printf("read %d \n ", w);
		word_print(w);
        }

        process(cur_node->children);
    }
}

/*
int streamFile(char *filename) {
    xmlTextReaderPtr reader;
    xmlNodePtr node;
    xmlNode n;
    
    int ret;

    reader = xmlNewTextReaderFilename(filename);
    if (reader != NULL) {

        ret = xmlTextReaderRead(reader);
        while (ret == 1) {
		if(xmlTextReaderDepth(reader)==0){
			node= xmlTextReaderExpand(reader);
			printf("process node %s\n",node->name);
        		    //processNode(reader);
        		//process(node);
                        process_end(node);
			//printf("process node\n");
			xmlTextReaderNext(reader);
		}
            ret = xmlTextReaderRead(reader);
        }
        xmlFreeTextReader(reader);
        if (ret != 0) {
            printf("%s : failed to parse\n", filename);
        }
    } else {
        printf("Unable to open %s\n", filename);
    }
}
*/

int main(char argc , char ** argv){
End tree;
FILE * out;
if(argc){
    tree= end_read_from_xml(argv[1]);
	//return streamFile(argv[1]);
    //_gdsl_bstree_write((gdsl_bstree_t)tree,&write_full_xml_node,fopen("bst.xml","w+"),NULL);
    //_gdsl_bstree_map_prefix((gdsl_bstree_t)tree,write_xml_node,fopen("bst.xml","w+"));
    end_serialize_as_xml(tree,fopen("teste.xml","w+"));
    endio_end_to_latex(tree,out=fopen("xmltree.tex","w+"));
    fclose(out);
}


return 0;
}
